package com.qyb.demo.threadpool1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <strong>实现功能:</strong>
 * <p></p>
 *
 * @author 秦有宝
 * @version 1.0.0  2019/1/23 8:59
 */
public class NewCachedThreadPoolDemo {


    public static void demo(){
        //定义ExecutorService实例
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();

        for (int i = 0; i < 10; i++) {
            final int index = i;
            try {
                Thread.sleep(index * 1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            //调用execute方法
            cachedThreadPool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread() + ":" + index);
                }
            });
        }


    }
}
